
import { Loading } from 'element-ui';

let loadMsg = "加载中……";

let loadingCount = 0;
let loading;

/* 点击显示加载框 */
export const isFlagClick = (flag)=>{
  if(flag){
    showLoading()
  }else{
    setTimeout(() => {
      hideLoading()
    }, 300);
  }
}

const startLoading = () => {
  loading = Loading.service({
    lock: true,
    text: loadMsg,
    background: 'rgba(255, 255, 255, 0.7)'
  });
};

const endLoading = () => {
  loading.close();
};

export const showLoading = () => {
  if (loadingCount === 0) {
    startLoading();
  }
  loadingCount += 1;
};

export const hideLoading = () => {
  if (loadingCount <= 0) {
    return;
  }
  loadingCount -= 1;
  if (loadingCount === 0) {
    endLoading();
  }
}
